class UpdatePosition < Mutations::Command
  include Wisper::Publisher

  required do
    model   :position
    string  :name
    string  :nature
  end

  def execute
    unless position_nature = Position::Nature.find_by_name(nature)
      add_error(:nature, :nature, '岗位类型不存在')
      return
    end
    position.name   = name
    position.nature = position_nature
    if position.save
      return position
    else
      position.errors.each do |key, value|
        add_error(key, key, value)
      end
    end
  end
end